<?php
ifi!perms_check('admin', 'config'))
{
	redirect('index.php?module=error&error=auth_error');
	exit;
}

if(!$_GET['cmd'])
{
	//create cat menu
	$cat_menu=array();
	$db->query("SELECT distinct cat FROM $conf[prefix]conf ORDER by cat ASC") or $db->err(__FILE__, __LINE__);
	while($d=$db->fetch_object()){
		if($_GET['cat']==$d->cat) $ttl='<b>'.strtoupper($d->cat).'</b>';
		else $ttl=strtoupper($d->cat);
		$cat_menu[]='<a href="index.php?module=admin&amp;action=conf&amp;cat='.$d->cat.'#cat_'.$d->cat.'">'.$ttl.'</a>';
	}
	//

	$fields=array('name', 'value');

	//sort
	if($_GET['sort']!='ASC' && $_GET['sort'] != 'DESC')
		$_GET['sort']='ASC';
	if(!$_GET['sortby'] or !in_array($_GET['sortby'], $fields))
		$_GET['sortby']='name';
	if($_GET['sort']=='ASC')
		$sortnext='DESC';
	else
		$sortnext='ASC';
	//


	$content='
		<form action="index.php" method="post">
		<input type="hidden" name="function" value="conf_edit" /> 
		<div>'.implode(' ', $cat_menu).'</div><br />
		<table border="0" width="100%" class="tabelka2">
		<tr>
		<td class="row_3" align="center"><a href="index.php?module=admin&action=conf&sortby=name&amp;sort='.$sortnext.'">'.$lang['conf_name'].'</a></td>
		<td class="row_3" align="center"><a href="index.php?module=admin&action=conf&sortby=value&amp;sort='.$sortnext.'">'.$lang['conf_value'].'</a></td>
		</tr>';
	$db = new dbquery;
	$db2 = new dbquery;
	$db2->query("SELECT DISTINCT cat FROM $conf[prefix]conf ORDER by cat $_GET[sort]") or $db->err(__FILE__, __LINE__);

	for($x=0;$x<$db2->num_rows();$x++)
	{

		$c=$db2->fetch_object();

		$content.='
			<tr>
			<td align="left"><a name="cat_'.$c->cat.'"></a><b>'.strtoupper($c->cat).'</b></td>
			</tr>';

		$db->query("SELECT * FROM $conf[prefix]conf WHERE cat='$c->cat' && type!='hidden' ORDER by $_GET[sortby] $_GET[sort]") or $db->err(__FILE__, __LINE__);

		for($y=0;$y<$db->num_rows();$y++) {
			$d=$db->fetch_object();	 

			$d->value=stripslashes($d->value);

			$i++;
			if($i>2)
				$i=1;

			if($_SESSION['lang_short']=='pl')
				$help=$d->help_pl;
			else
				$help=$d->help_en;

			if($d->type=='textarea')
				$type='<textarea cols="'.$d->size.'" rows="8" name="'.$d->name.'" class="button">'.$d->value.'</textarea>';
			elseif($d->type=='bool')
			{
				if($d->value==1)
					$checked='CHECKED';
				else
					$checked='';

				$type='<input type="checkbox" name="'.$d->name.'" value="1" class="button" '.$checked.' />';
			}
			else
				$type='<input type="text" size="'.$d->size.'" name="'.$d->name.'" value="'.$d->value.'" class="button" />';

			$content.='
				<tr valign="top">
				<td width="200" class="row_'.$i.'" align="left">$conf[\''.$d->name.'\']<br /><small>'.$help.'<small></td>
				<td class="row_'.$i.'" align="left">&nbsp;'.$type.'</td>
				</tr>';
		}

		$content.='<tr>
			<td class="row_3"></td>
			<td class="row_3"><input type="submit" value="'.$lang['admin_edit'].'" class="button" /> <input type="button" onclick="javascript: document.location=\'#\'; " value="Top" class="button" /></small></td>
			</tr>';
	}


	$content.='
		</table>
		<br /><div>'.implode(' ', $cat_menu).'</div>
		</form>'; 

	$content=string_template(read_file('middle.php'), array('theme_path' => $GLOBALS['theme_path'], 'content' => $content, 'description' => $lang['conf_description']));
}
?>
